<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/xadmin.css}">
    <script th:src="@{/webjars/jquery/3.5.1/jquery.min.js}"></script>
    <script th:src="@{/js/ions_alert.js}"></script>
    <script th:src="@{/common/common.js}"></script>
    <script th:src="@{/js/sweetalert.min.js}"></script>
    <link rel="stylesheet" th:href="@{/css/sweetalert.css}">
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">演示</a>
        <a>
          <cite>导航元素</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <dd class="layui-form layui-col-md12 x-so">
            <button class="layui-btn" lay-submit="" lay-filter="search" id="search"><i class="layui-icon" >&#xe615;</i></button>
        </dd>
    </div>
    <xblock>
        <span class="x-right" style="line-height:40px">共有数据：<span id ="many" style="color: #bf1707" text="${WARE_PAGE_LIST.getTotalCount()}"></span>条</span>
    </xblock>
    <table class="layui-table middle">
        <thead>
        <tr>
            <th width="6%">
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i
                        class="layui-icon">&#xe605;</i></div>
            </th>
            <th>商品码</th>
            <th>商品名</th>
            <th>商品数量</th>
            <th>进价</th>
            <th>售价</th>
            <th>积分</th>
            <th>状态</th>
            <th>修改者</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody id="tbody" class="waresList">
        </tbody>
    </table>
    <div class="page" id="page">
        <div>
            <span class="current" id="allPage" text="${'共'+WARE_PAGE_LIST.getTotalPage()+'页'}">共0页</span>
            <!--            <a class="prev" href="{{urlfor "AuthController.List"}}?page={{.pageMap.firstPage}}&keyword={{.keyword}}"><&lt;</a>-->
            <a class="prev" href="javaScript:" id="begin" onclick="pageGo('begin')"><&lt;</a>
            <a class="prev" href="javaScript:" onclick="pageGo('forward')">&lt;</a>
            <span class="current" id="currentPage" text="${WARE_PAGE_LIST.getCurrentPage()+1}">0</span>
            <!--            <a class="next" href="#" >啊</a>-->
            <a class="next" href="javaScript:" onclick="pageGo('nextPage')">&gt;</a>
            <a class="next" href="javaScript:" onclick="pageGo('end')">&gt;&gt;</a>
        </div>
    </div>

</div>
<script>

    $(function () {
        $("#search").click(function () {
            findPage(0,1,'search');
        })
    });

    function pageGo(param){
        let currentPage = $("#currentPage").text();
        let allPage = $("#allPage").text();
        if(currentPage < allPage){
            currentPage --;
        }
        findPage(currentPage,allPage,param);
    }

    function findPage(currentPage,allPage,param){
        $.ajax({
            url:"/admin/wares/findWaresListDel",
            type:"GET",
            data:{
                currentPage:currentPage,
                allPage:allPage,
                param:param
            },
            success:function (ResultInfo) {
                console.log(ResultInfo);
                if(ResultInfo.flag){
                    var text = '';
                    for (let i = 0; i < ResultInfo.data.list.length; i++) {
                        text += '<tr>\n' +
                            '            <td>\n' +
                            '                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id=\'2\'><i\n' +
                            '                        class="layui-icon">&#xe605;</i></div>\n' +
                            '            </td>\n' +
                            '            <td id="id" th:text="${wares.getNo()}">'+ResultInfo.data.list[i].no+'</td>\n' +
                            '            <td id="name" th:text="${wares.getName()}">'+ResultInfo.data.list[i].name+'</td>\n' +
                            '            <td id="number" th:text="${wares.getNumber()}">'+ResultInfo.data.list[i].number+'</td>\n' +
                            '            <td id="in_price" th:text="${wares.getTradePrice()}">'+ResultInfo.data.list[i].tradePrice+'</td>\n' +
                            '            <td id="out_price" th:text="${wares.getRetailPrice()}">'+ResultInfo.data.list[i].retailPrice+'</td>\n' +
                            '            <td id="point" th:text="${wares.getPoints()}">'+ResultInfo.data.list[i].points+'</td>\n';
                        if(ResultInfo.data.list[i].waresStatus === '下架') {
                            text +=
                                '            <td class="td-status">\n' +
                                '                <span class="layui-btn layui-btn-danger layui-btn-mini" >下架</span>\n' +
                                '            </td>\n';
                        }
                        text +='            <td id="modify">'+ResultInfo.data.list[i].lastArchivist+'</td>\n' +
                            '                <td><a href="javascript:" onclick="addDelWaresConfirm('+ResultInfo.data.list[i].no+')"' +
                            '                    style="cursor: pointer" class="layui-btn layui-btn-mini layui-btn-normal">\n' +
                            '                    <i class="layui-icon">&#xe642;</i>上架\n' +
                            '                </a></td>\n' +
                            '        </tr>';
                        text += '';
                        $(".waresList").html(text);
                        $("#currentPage").html(ResultInfo.data.currentPage+1);
                        $("#allPage").html('共'+ResultInfo.data.totalPage+'页');
                        $("#many").text(ResultInfo.data.totalCount);
                    }
                    text += '';


                }else {
                    console.log(ResultInfo.message);
                }
            },
            error:function (e) {
                alert("出错了");
            }
        })
    }
    function addDelWaresConfirm(no) {
        let b = confirm("确认上架吗？");
        if(b){
            console.log(no);
            $.ajax({
                url:"/admin/wares/addDelWares",
                data:{
                    no:no
                },
                success:function (resultInfo) {
                    if(resultInfo.flag){
                        alert(resultInfo.message);
                        location.reload();
                    }else {
                        alert(resultInfo.message);
                    }
                }
            })
        }
    }
</script>
</body>
</html>